package com.itheima.controller;

import com.itheima.goods.pojo.Goods;
import com.itheima.service.GoodsService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/goods")
@CrossOrigin
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    //查询所有
    @GetMapping
    public Result findAll(){
        return goodsService.findAll();
    }
    //添加用户
    @PostMapping
    public Result add(Goods goods){
        return goodsService.add(goods);
    }
    //分页查询
    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page")int page, @PathVariable("size")int size){
       return goodsService.findPage(page, size);
    }
    //根据id查询
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") Integer id){
        return goodsService.findById(id);
    }
    //根据id修改
    @PutMapping("/{id}")
    public Result update(@PathVariable("id") Integer id,Goods goods){
        return goodsService.updateById(id,goods);
    }
    //根据id删除
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id")Integer id){
        return goodsService.delete(id);
    }

}
